package servlet;

import beans.SMS;
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/codeSend")
public class MyServlet_SendCode extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int appID = 1400517293;
        String appkey="";
//        appkey = "02ae3cfde868c1b632fd9f3e21209406";
        int templateID = 947528;
        String smsSign = "yfuxTest公众号";
        try {
            String mobile = req.getParameter("mobile");
            String code = req.getParameter("code");
            System.out.println("验证码为: "+code);
            String[] params = {code,"2"};
            SmsSingleSender sender = new SmsSingleSender(appID, appkey);
            System.out.println(req.getParameter("mobile"));
            SmsSingleSenderResult result = sender.sendWithParam("86",mobile ,
                    templateID, params, smsSign, "", "");
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
